<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Category;

class UserController extends Controller
{
    function __construct(Request $request){
        $this->admin = $request->session()->get('admin', false);
        $this->data = ['admin' => $this->admin,
                    'categorys' => Category::all(),
                    ];

    }
    public function login(){
    	return view('blog.login',$this->data);
    }
    public function verify(Request $request){
    	$input = $request->all();
    	if (trim($input['password']) == env('LOGIN_PASSWORD')){
    		session(['admin' => 'kaychen']);
    	}
    	return redirect('/');
    }
    public function logout(Request $request){
    	// $request->session()->forget('admin');
    	$request->session()->flush();
    	return redirect('/');
    }

}
